In [39]:
import pandas as pd
import numpy as np
import plotly.express as px
In [4]:
df = pd.read_csv("mobile.csv")
In [5]:
df[['ram', 'rom', 'ssd', 'price']].isnull().sum()
df['ram_clean'] = df['ram'].str.extract(r'(\d+)').astype(float)
df['rom_clean'] = df['rom'].str.extract(r'(\d+)').astype(float)
In [6]:
def convert_storage(value):
if pd.isna(value):
return np.nan
value = value.upper()
if "TB" in value:
return float(value.replace("TB", "")) * 1024
elif "GB" in value:
return float(value.replace("GB", ""))
else:
return np.nan
df['ssd_clean'] = df['ssd'].apply(convert_storage)
In [7]:
df['spec_score'] = df['ram_clean'] + df['rom_clean'] + df['ssd_clean'].fillna(0) * 2
In [8]:
df["value_for_money"] = df['spec_score']/df["price"]
In [9]:
df.head()
Out[9]:
| Unnamed: 0 | product | brand | product_code | product_specification | price | inward_date | dispacth_date | quantity_sold | customer_name | ... | core_specification | processor_specification | ram | rom | ssd | ram_clean | rom_clean | ssd_clean | spec_score | value_for_money | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | Mobile Phone | Motorola | 88EB4558 | Site candidate activity company there bit insi... | 78570 | 2023-08-02 | 2023-08-03 | 6 | William Hess | ... | NaN | Snapdragon 7 Gen | 12GB | 128GB | NaN | 12.0 | 128.0 | NaN | 140.0 | 0.001782 |
| 1 | 1 | Laptop | Oppo | 416DFEEB | Beat put care fight affect address his. | 44613 | 2023-10-03 | 2023-10-06 | 1 | Larry Smith | ... | Ryzen 5 | Ryzen 5 | 8GB | 512GB | 256GB | 8.0 | 512.0 | 256.0 | 1032.0 | 0.023132 |
| 2 | 2 | Mobile Phone | Samsung | 9F975B08 | Energy special low seven place audience. | 159826 | 2025-03-19 | 2025-03-20 | 5 | Leah Copeland | ... | NaN | MediaTek Dimensity | 8GB | 256GB | NaN | 8.0 | 256.0 | NaN | 264.0 | 0.001652 |
| 3 | 3 | Laptop | Sony | 73D2A7CC | Friend record hard contain minute we role sea ... | 20911 | 2024-02-06 | 2024-03-27 | 1 | Dan Kirby | ... | i7 | i7 | 12GB | 64GB | 2TB | 12.0 | 64.0 | 2048.0 | 4172.0 | 0.199512 |
| 4 | 4 | Laptop | Microsoft | CCE0B80D | Program recently feeling save tree hotel people. | 69832 | 2023-08-10 | 2023-09-10 | 4 | Dean Martin | ... | i7 | i7 | 8GB | 128GB | 2TB | 8.0 | 128.0 | 2048.0 | 4232.0 | 0.060603 |
5 rows × 22 columns
In [20]:
brand_vfm = df.groupby('brand')['value_for_money'].mean().sort_values(ascending=False)
In [22]:
brand_vfm
Out[22]:
brand Dell 0.024006 Vivo 0.022915 OnePlus 0.022615 Acer 0.022368 Apple 0.022306 Samsung 0.022281 Asus 0.022261 Oppo 0.022250 Redmi 0.021973 Huawei 0.021890 Google 0.021844 Nokia 0.021560 Motorola 0.021337 Toshiba 0.021108 Realme 0.021092 Sony 0.021024 HP 0.020730 iQOO 0.020337 Lenovo 0.020296 Microsoft 0.019970 Name: value_for_money, dtype: float64
In [24]:
top_10_vfm = brand_vfm.head(10).reset_index()
In [52]:
top_10_vfm.columns = ['Brands', 'Value for money']
top_10_vfm
Out[52]:
| Brands | Value for money | |
|---|---|---|
| 0 | Dell | 0.024006 |
| 1 | Vivo | 0.022915 |
| 2 | OnePlus | 0.022615 |
| 3 | Acer | 0.022368 |
| 4 | Apple | 0.022306 |
| 5 | Samsung | 0.022281 |
| 6 | Asus | 0.022261 |
| 7 | Oppo | 0.022250 |
| 8 | Redmi | 0.021973 |
| 9 | Huawei | 0.021890 |
In [69]:
fig = px.bar(
top_10_vfm,
x='Brands',
y='Value for money',
title='Top 10 Brand dengan Value for Money Tertinggi',
text='Value for money',
color='Brands',
color_continuous_scale='viridis'
)
In [74]:
fig.update_traces(texttemplate='%{text:.4f}', textposition='outside')
fig.update_layout(
xaxis_title='Brands',
yaxis_title='Rata-rata Value for Money',
uniformtext_minsize=8,
uniformtext_mode='hide',
showlegend=False
)
In [ ]: